package com.molyfun.parents.fragment.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.setting.MineActivity;
import com.molyfun.parents.fragment.BaseFragment;
import com.molyfun.parents.view.HorizonalThreeTabBar;
import com.molyfun.parents.view.MineMsgAdapter;
import com.molyfun.parents.view.ThreeTabBar;
import com.molyfun.parents.view.ZNViewPager;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by ZhaoWei on 2016/12/5.
 * 首页-我的消息
 */

public class MineMsgFragment extends BaseFragment implements View.OnClickListener, ThreeTabBar.ThreeBarClickListener {

    @InjectView(R.id.three_tab_bar)
    HorizonalThreeTabBar mHorizonalThreeTabBar;
    @InjectView(R.id.viewpager)
    ZNViewPager viewpager;
    @InjectView(R.id.profile_icon)
    ImageView mProfileIcon;

    private MineMsgAdapter pagerAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine_msg, container, false);
        ButterKnife.inject(this, view);

        mHorizonalThreeTabBar.initData("聊天", "咨询", "系统");
        initViewPager();
        mHorizonalThreeTabBar.setThreeBarClickListener(this);
        mProfileIcon.setOnClickListener(this);

        return view;
    }

    @Override
    public void onThreeBarClick(int chooseTab) {
        switch (chooseTab) {
            case ThreeTabBar.ThreeTabChooseTab.BAR_ONE:
                viewpager.setCurrentItem(0, false);
                break;
            case ThreeTabBar.ThreeTabChooseTab.BAR_TWO:
                viewpager.setCurrentItem(1, false);
                break;
            case ThreeTabBar.ThreeTabChooseTab.BAR_THREE:
                viewpager.setCurrentItem(2, false);
                break;
        }
    }

    private void initViewPager() {
        viewpager.setScrollEnable(false);
        viewpager.setOffscreenPageLimit(3);
        pagerAdapter = new MineMsgAdapter(getChildFragmentManager());
        viewpager.setAdapter(pagerAdapter);
        viewpager.setCurrentItem(0);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.profile_icon:
                MineActivity.startActivity(getContext());
                break;
        }
    }

}
